from datetime import datetime


def parse_line(line):
    time_str = line.split()[0] + ' ' + line.split()[1]
    return datetime.strptime(time_str, '%Y-%m-%d %H:%M:%S.%f')


def calculate_time_differences(lines):
    time_differences = []

    for i in range(0, len(lines), 2):
        time1 = parse_line(lines[i])
        time2 = parse_line(lines[i + 1])
        time_diff = (time2 - time1).total_seconds()
        time_differences.append(time_diff)

    return time_differences


def find_minimum_difference(time_differences):
    return min(time_differences)


def main():
    # 假设文件名为 "data.txt"
    with open("test_1121.txt", "r") as file:
        lines = file.readlines()

    # 去除每行末尾的换行符
    lines = [line.strip() for line in lines]

    time_differences = calculate_time_differences(lines)
    min_difference = min(time_differences)
    max_difference = max(time_differences)
    print(f"--------: {time_differences}")
    print(f"--------size: {len(time_differences)}")
    print(f"最小时间差是: {min_difference} 秒")
    print(f"最大时间差是: {max_difference} 秒")


if __name__ == "__main__":
    main()
